<?

/**************************************************************************************************************************************
1	Normal File upload		:  generalfileupload($original , $foldername)           					
2  	Imageuploadwithresizing :  resizingimage($original, $bigimage, $thumbnail, $height, $width)   
3	Country name using id	:	getcountryname($countryid, $dbObj, $tbl)     
4	Padding to digits		:	PadDigit($digit)
5	Removing padding		:	RemovePad($digit)
6	mailsend using phpmailer:	sendmailer($sender, $sendername, $subject, $mailcontent, $receiver, $receivername)
7	send html email 		:	SendHTMLMail($to,$subject,$mailcontent,$from)
8	normal mail function	:	SendMail($to,$subject,$mailcontent,$from)
9	random password geneart :   randompasword()
10	Calucaltes age of person:	get_age($dob)
11	Encoding IP address		:	encode_ip($dotquad_ip)
12	Decoding IP address		:	decode_ip($dotquad_ip)
13	Binary to ASCII			:	bin2asc($binaryInput, $byteLength=8)
14	ASCII to Binary			:	asc2bin($inputstring, $byteLength=8)
**************************************************************************************************************************************/
	
/********************************************************************
  General file uploading
******************************************************************/

	
	function generalfileupload($original , $foldername, $nameflag)
	{
		if($original['name']!== "")
		{			
			if($nameflag)
			$newname = date("Ymd_His").str_replace(" ", "_", $original['name']);
			else
			$newname = $original['name'];
				 
			 $fullpath = $foldername."/".$newname;	 
			 
			$cpy = copy($original['tmp_name'], $fullpath);
			
			if($cpy) return $newname;
			else return 0;
		}
	}

	
	function generalfileuploadname($original , $foldername, $nameflag)
	{
		if($original!== "")
		{			
			if($nameflag)
			$newname = date("Ymd_His").str_replace(" ", "_", $original);
			else
			$newname = $original;
				 
			 $fullpath = $foldername."/".$newname;	 
// 			 echo $original;
			 $cpy = move_uploaded_file($newname, $foldername); 
			
			if($cpy) return $newname;
			else return 0;
		}
	}
	
	function uploadandresize($original, $bigImgPath, $thumbPath, $height, $width)
	{
		if($original['name']!== "")
		{
			$image_type = $original["type"];
			if($image_type=="image/pjpeg" || $image_type=="image/jpeg" || $image_type=="image/gif" || $image_type=="image/png" || $img_type="image/x-png")
			{
				include_once("resize.php");
				$DEST_FILE= $bigImgPath . "/" . date("YmdHis") . str_replace(" ", "_", $original['name']);
				$THUMB_FILE= $thumbPath . "/" . date("YmdHis") . str_replace(" ", "_", $original['name']); 
				copy($original['tmp_name'],  $DEST_FILE);
				$thumb=new thumbnail($DEST_FILE);			// generate image_file, set filename to resize
				$thumb->size_width($width);				// set width for thumbnail, or
				$thumb->size_height($height);				// set height for thumbnail, or
				if($width > $height)
					$thumb->size_auto($width);					// set the biggest width or height for thumbnail
				else
					$thumb->size_auto($height);
					
				$thumb->jpeg_quality(75);				// [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75
				$thumb->jpeg_quality(75);
				$thumb->save($THUMB_FILE);
				$photos = array('thumbnail'=>basename($THUMB_FILE), 'bigphoto'=>basename($DEST_FILE));
				return $photos;
			}
		}
	}
	
/*******************************************************************
new resizing function
/*******************************************************************/

   function resizingimagenew($original, $bigimage, $thumbnail, $height, $width)
	{ 
		if($original['name']!== "")
		{ //start of loop
			$target_path = $bigimage.'/';
			$basename=time().basename($original['name']);
			//$basename="big".time();
			$target_path = $target_path.$basename; 
		
			$SMALL_IMAGE_PATH= $thumbnail;
			$SMALL_IMAGE_NEW_WIDTH= $height;
			$SMALL_IMAGE_NEW_HEIGHT= $width;
	 
			$image_name = $original["name"];
			$image_type = $original["type"];
			$image_temp = $original["tmp_name"];
	  
	 		$uniquepriceid =md5(uniqid(rand()));
			
			if($image_type=="image/pjpeg" || $image_type=="image/jpeg" || $image_type=="image/gif")
      	 	{  	
			   $v_value=uniqid(date(s));
			   if($image_type=="image/pjpeg" || $image_type== "image/gif" || $image_type=="image/jpeg") 
			   {
				   
					
					 $SMALL_IMAGE_NEW_WIDTH= $width;
					 $SMALL_IMAGE_NEW_HEIGHT= $height; 
					 
				   if($image_type=="image/jpeg" || $image_type=="image/pjpeg")
				   {
						$smallimage_name="thumb".$v_value.".jpg";
						$smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;
						$im = ImageCreateFromJPEG($image_temp);
						if(!$im)
						$Error = 6;
					}
					if($image_type=="image/gif")
					{
						 $smallimage_name="thumb".$v_value.".gif";
						 $smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;
						 $im = ImageCreateFromGIF($image_temp);
					}
					 
					 $OldWidth  = ImageSX($im);
					 $OldHeight = ImageSY($im);
					 $small_image = imagecreatetruecolor ($SMALL_IMAGE_NEW_WIDTH, $SMALL_IMAGE_NEW_HEIGHT );
						

   ImageCopyResized($small_image,$im,0,0,0,0,$SMALL_IMAGE_NEW_WIDTH, $SMALL_IMAGE_NEW_HEIGHT, $OldWidth,$OldHeight);
					 ImageJpeg($small_image,$smallimage_path,180);
								 
					 //$bigimagename=time();

						if($image_type=="image/jpeg" || $image_type=="image/pjpeg")
						{
							$bigimagename = "big".$v_value.".jpg";
						}
						else if($image_type=="image/gif")
						{
							$bigimagename = "big".$v_value.".gif";
						}

					 $bigimagepath = $bigimage."/".$bigimagename;
					 $LARGE_IMAGE_NEW_WIDTH = $OldWidth;
					 $LARGE_IMAGE_NEW_HEIGHT = $OldHeight;
								 
					 $big_image = imagecreatetruecolor ($LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT );
					 ImageCopyResized($big_image,$im,0,0,0,0, $LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT , $OldWidth,$OldHeight);
					 ImageJpeg($big_image,$bigimagepath,180);
					 
					 
					 @copy($big_image, $bigimagepath);
					//echo $smallimage_name;
					 if($bigimagename && $smallimage_name)
					  {
					 	$imagenames = array($bigimagename, $smallimage_name);	
						return $imagenames;
					 }	
					
				} 
			}	
		}    
	}	


	
	function img_aspect_ratio($req_ht,$req_wt,$size)
	{
		$wt = $size[0];
		$ht = $size[1];

		$mul_height=$req_ht*100;
		if($ht > 0 )
			$div_height=$mul_height/$ht;
		
		$mul_width=$req_wt*100;
		if($wt > 0 )
			$div_width=$mul_width/$wt;

		if($div_width < $div_height)
		{ 
			$conversion_factor= $div_width;
			$finalwidth = $req_wt;
			$finalheight = ($ht*$conversion_factor)/100;
		}
		else if($div_width > $div_height)
		{
			$conversion_factor= $div_height;
			$finalwidth = ($wt*$conversion_factor)/100;
			$finalheight = $req_ht;
		}
		else 
		{
			$finalwidth =$wt;
			$finalheight = $ht;
		}
		$array_img['finalwidth']=$finalwidth;
		$array_img['finalheight']=$finalheight;
		return $array_img;
	}
	/*******************************************************************/

function resize_multiple_images($file_parameter,$width_array,$path_array,$original_img_path,$height_array=0)
	{
		$image =$file_parameter["name"];
		$uploadedfile = $file_parameter['tmp_name'];
		if ($image) 
		{ 	
			$filename = stripslashes($file_parameter['name']);
			$extension = getExtension($filename);
			$extension = strtolower($extension);
		
		
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif") && ($extension != "JPG") && ($extension != "JPEG") && ($extension != "PNG") && ($extension != "GIF"))
			{
		
				$change='<div class="msgdiv">Unknown Image extension </div> ';
				$errors=1;
			}
			else
			{
				$size=filesize($file_parameter['tmp_name']);
				if ($size > MAX_SIZE*1024*20)
				{
					$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
					$errors=1;
				}

				if($extension=="jpg" || $extension=="jpeg" || $extension=="JPG" || $extension=="JPEG")
				{
					$uploadedfile = $file_parameter['tmp_name'];
					$src = @imagecreatefromjpeg($uploadedfile);
				}
				else if($extension=="png" || $extension=="PNG")
				{
					$uploadedfile = $file_parameter['tmp_name'];
					$src = imagecreatefrompng($uploadedfile);
				}
				else 
				{
					$src = imagecreatefromgif($uploadedfile);
				}

		//	echo $scr;

		list($width,$height)=getimagesize($uploadedfile);
		/*$random = createRandomPassword();*///for creating other name of file
// 			$random = "";
			$origsize = getimagesize($uploadedfile);
			for($i=0;$i<sizeof($width_array);$i++)
			{
				if($height_array==0)
				{
					$newwidth=$width_array[$i];
					$newheight=($height/$width)*$width_array[$i];
					$tmp=imagecreatetruecolor($newwidth,$newheight);
				}
				else
				{
					$image_ratio_display=img_aspect_ratio($height_array[$i],$width_array[$i],$origsize);
					$newwidth=$image_ratio_display['finalwidth'];
					$newheight=$image_ratio_display['finalheight'];
					$tmp=imagecreatetruecolor($newwidth,$newheight);
				}
				@imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// 				if($originalname==1)
// 				{
// 					$changed_file_name=$file_parameter['name'];
// 				}
// 				else
// 				{
					//$filename = $path_array[$i].$file_parameter['name'];
					$res= explode('.', $file_parameter['name']);  //for creating other name of file
		$res[0].=$random;
		$changed_file_name= implode(".", $res);
// 				}
				$filename = $path_array[$i].$changed_file_name;

				imagejpeg($tmp,$filename,100);
				
				@imagedestroy($tmp);
			}
			//code added for storing original image....
					$original_image_name = $original_img_path."/".$changed_file_name;
			@copy($uploadedfile, $original_image_name);
			
			@imagedestroy($src);
			
			return($changed_file_name);

			}
		}
	}
	
	
	
/********************************************************************
   Created by : Archana Mapari
   Date       : 22/11/2008
   Runtime resizing of image 
********************************************************************/
    function resizingimage_bysize($original, $bigimage, $thumbnail, $height, $width)
	{ 
		if($original['name']!== "")
		{ //start of loop
			$target_path = $bigimage.'/';
			$basename=time().basename($original['name']);			
			$target_path = $target_path.$basename; 
		
			$SMALL_IMAGE_PATH= $thumbnail;
			$SMALL_IMAGE_NEW_WIDTH= $width;
			$SMALL_IMAGE_NEW_HEIGHT= $height;
	 
			$image_name = $original["name"];
			$image_type = $original["type"];
			 $image_temp = $original["tmp_name"];
	  
	 		$uniquepriceid =md5(uniqid(rand()));
      	 	if($image_type=="image/pjpeg" || $image_type=="image/jpeg" || $image_type=="image/gif")
      	 	{  	
			   $v_value=uniqid(date(s));
			   if($image_type=="image/pjpeg" || $image_type== "image/gif" || $image_type=="image/jpeg") 
			   {
				   $mysock = getimagesize($image_temp);
					$target=100;
				 
					 $SMALL_IMAGE_NEW_WIDTH= $width;
					 $SMALL_IMAGE_NEW_HEIGHT= $height; 
					 
				   if($image_type=="image/jpeg" || $image_type=="image/pjpeg")
				   {
						$smallimage_name="thumb".$v_value.".jpg";
						$smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;
						$im = ImageCreateFromJPEG($image_temp);
						if(!$im)
						$Error = 6;
					}
					
					if($image_type=="image/gif")
					{						
						 $smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;	
						 $im = ImageCreateFromGIF($image_temp);
					}
					 
					 $OldWidth  = ImageSX($im);
					 $OldHeight = ImageSY($im);
					 $small_image = imagecreatetruecolor ($SMALL_IMAGE_NEW_WIDTH, $SMALL_IMAGE_NEW_HEIGHT );
					 ImageCopyResized($small_image,$im,0,0,0,0,$SMALL_IMAGE_NEW_WIDTH, $SMALL_IMAGE_NEW_HEIGHT, $OldWidth,$OldHeight);
					 ImageJpeg($small_image,$smallimage_path,100);
					
						if($image_type=="image/jpeg" || $image_type=="image/pjpeg")
						{
							$bigimagename = "big".$v_value.".jpg";
						}
						else if($image_type=="image/gif")
						{
							$bigimagename = "big".$v_value.".gif";
						}

					 $bigimagepath = $bigimage."/".$bigimagename;
					 $LARGE_IMAGE_NEW_WIDTH = $OldWidth;
					 $LARGE_IMAGE_NEW_HEIGHT = $OldHeight;
								 
					 $big_image = imagecreatetruecolor ($LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT );
					 ImageCopyResized($big_image,$im,0,0,0,0, $LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT , $OldWidth,$OldHeight);
					 ImageJpeg($big_image,$bigimagepath,100);				 
					 
					 @copy($big_image, $bigimagepath);
					
					 if($bigimagename && $smallimage_name)
					  {
					 	$imagenames = array($bigimagename, $smallimage_name);	
						return $imagenames;
					 }	
					
				} 
			}	
		}    
	}	


//padding to one length numerics
  function PadDigit($digit)
  {
    if($digit<=9)
      $digit = "0".$digit;
    return $digit;
  }
/********************************************************************
    Remove Pad Ex 01 becomes 1
********************************************************************/

  function RemovePad($digit)
  {
    if($digit[0]=='0')
      $ret = $digit[1];
    else
      $ret = $digit;
    return $ret;
  }

  
 /********************************************************************
   Mail sending using PHP mailer function
 ********************************************************************/ 
 function sendmailer($sender, $sendername, $subject, $mailcontent, $receiver, $receivername)
 {
  	include("class.phpmailer.php");
	
 	$mail = new phpmailer();
	$mail->IsSMTP();
	$mail->Host = "mail.salenoffers.com";
	$mail->Port = 26;
	$mail->SMTPAuth = true;
	$mail->Username = "contact@salenoffers.com";  // Write SMTP username in ""
	$mail->Password = "sno130508";
	$mail->Mailer   = "smtp";
	$mail->IsHTML(true);
	$mail->ClearAddresses();
	
	$mail->From     =  $sender;
	$mail->FromName =  $sendername;
	$mail->Subject  =  $subject;	
	$mail->Body  = $mailcontent;
	$mail->AddAddress($receiver, $receivername);
	$suc = $mail->Send();
	if($suc >0)	return 1;
	else return 0;
 }

//  function sendmailer($sender, $sendername, $subject, $mailcontent, $receiver, $receivername)
//  {
// 	include_once("class.phpmailer.php");
// 	
//  	$mail = new phpmailer();
// 	$mail->From     =  $sender;
// 	$mail->FromName =  $sendername;
// 	$mail->Subject  =  $subject;
// 	$mail->SMTPAuth = true;
// 	$mail->Host     = "mail.AGILETECHNOSYS.com"; 
// 	$mail->Username = "m.rajesh@AGILETECHNOSYS.com";  // Write SMTP username in ""
// 	$mail->Password = "rajesh?2007";
// 	$mail->Mailer   = "smtp";
// 	$mail->IsHTML(true);
// 	$mail->Body  = $mailcontent;
// 	$mail->ClearAddresses();
// 	$mail->AddAddress($receiver, $receivername);
// 	$suc = $mail->Send();
// 	if($suc >0)	return 1;
// 	else return 0;
//  }
 /******************************************************************************************
	 Random password generator 
 *****************************************************************************************/
function randompassword()
{
	 $password = "";
	  $possible = "0123456789abcdefghjkmnpqrstvwxyz"; 
	  $i = 0; 
	
	while ($i < 8) 
	{ 
	   $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
		
	   if (!strstr($password, $char)) 
	   { 
		$password .= $char;
		$i++;
		}
	}
	return $password;
 } 
 /******************************************************************************************
//calculate the age of the persons
******************************************************************************************/
function get_age($dob)
{
    $ageparts = explode("-",$dob);
    $today = date('Y-m-d');
    $todayparts = explode("-",$today);
    $age=  $todayparts[0]-$ageparts[0];
    $month=$todayparts[1]-$ageparts[1];
    $day=  $todayparts[2]-$ageparts[2];
    return floor($age+($month/12)+($day/365));   
} 
/******************************************************************************************
	Encodes the IP Address
******************************************************************************************/
function encode_ip($dotquad_ip)
{
	$ip_sep = explode('.', $dotquad_ip);
	return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
}
/******************************************************************************************
	Encodes the IP Address
******************************************************************************************/
function decode_ip($int_ip)
{
	$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
	return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}
/******************************************************************************************
// convert an input string into it's binary equivalent.
******************************************************************************************/
function asc2bin($inputString, $byteLength=8)
{
	$binaryOutput = '';
	$strSize = strlen($inputString);

	for($x=0; $x<$strSize; $x++)
	{
		$charBin = decbin(ord($inputString{$x}));
		$charBin = str_pad($charBin, $byteLength, '0', STR_PAD_LEFT);
		$binaryOutput .= $charBin;
	}

	return $binaryOutput;
}

/******************************************************************************************
// convert an binary to ascii string
******************************************************************************************/
function bin2asc($binaryInput, $byteLength=8)
{
	if (strlen($binaryInput) % $byteLength)
	{
		return false;
	}
	
	// why run strlen() so many times in a loop? Use of constants = speed increase.
	$strSize = strlen($binaryInput);
	$origStr = '';

	// jump between bytes.
	for($x=0; $x<$strSize; $x += $byteLength)
	{
		// extract character's binary code
		$charBinary = substr($binaryInput, $x, $byteLength);
		$origStr .= chr(bindec($charBinary)); // conversion to ASCII.
	}
	return $origStr;
}

function limit_text( $text, $limit )
{
  // figure out the total length of the string
  if( strlen($text)>$limit )
  {
    # cut the text
    $text = substr( $text,0,$limit );
    # lose any incomplete word at the end
    $text = substr( $text,0,-(strlen(strrchr($text,' '))) );
  }

  // return the processed string
  return $text;
}

// convert date to One single format
function convertDate($date)
{
  $ex_date =  explode("-", $date);
  $converted_date = @date("F j, Y", @mktime(0,0,0,$ex_date[1], $ex_date[2], $ex_date[0]));

  return $converted_date;
}

/* Tutorial by AwesomePHP.com -> www.AwesomePHP.com */
/* Function: Get time difference between two dates at specific format */ 
/* Date Format: YYYY-MM-DD HH:SS:SP */
/*
echo 'I am: '.getDifference(date("Y-m-d G:i:s"),'1980-08-05 00:00:00'). '
Years old';
*/
function getDifference($startDate,$endDate,$format = 6)
{
    list($date,$time) = explode(' ',$endDate);
    $startdate = explode("-",$date);
    $starttime = explode(":",$time);

    list($date,$time) = explode(' ',$startDate);
    $enddate = explode("-",$date);
    $endtime = explode(":",$time);

    $secondsDifference = mktime($endtime[0],$endtime[1],$endtime[2],
        $enddate[1],$enddate[2],$enddate[0]) - mktime($starttime[0],
            $starttime[1],$starttime[2],$startdate[1],$startdate[2],$startdate[0]);
    
    switch($format){
        // Difference in Minutes
        case 1: 
            return floor($secondsDifference/60);
        // Difference in Hours    
        case 2:
            return floor($secondsDifference/60/60);
        // Difference in Days    
        case 3:
            return floor($secondsDifference/60/60/24);
        // Difference in Weeks    
        case 4:
            return floor($secondsDifference/60/60/24/7);
        // Difference in Months    
        case 5:
            return floor($secondsDifference/60/60/24/7/4);
        // Difference in Years    
        default:
            return floor($secondsDifference/365/60/60/24);
    }                
}

	function validateEmail($email){
	
		$pattern_email = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z]{2,6})*(\.[a-z]{2,3})$";
	
		if(($email === "") || (empty($email)) || (strlen($email) === 0)){
	
			return(false);
		} else if(eregi($pattern_email, $email)){
	
			return(true);
		}
	
		return(false);
	}
	function resizingimageadd($original, $bigimage, $thumbnail, $height, $width)
	{ 


		if($original['name']!== "")

		{ //start of loop

			$target_path = $bigimage.'/';

			$basename=time().basename($original['name']);

			//$basename="big".time();

			$target_path = $target_path.$basename; 

			$widthadd = $width;

			$heightadd = $height;  

			$SMALL_IMAGE_PATH= $thumbnail;

			$SMALL_IMAGE_NEW_WIDTH= $widthadd;

			$SMALL_IMAGE_NEW_HEIGHT= $heightadd;

	 

			$image_name = $original["name"];

			$image_type = $original["type"];

			 $image_temp = $original["tmp_name"];

	  

	 		$uniquepriceid =md5(uniqid(rand()));

      	 	if($image_type=="image/pjpeg" || $image_type=="image/jpeg" || $image_type=="image/gif")

      	 	{  


			   $v_value=uniqid(date(s));

			   if($image_type=="image/pjpeg" || $image_type== "image/gif" || $image_type=="image/jpeg") 

			   {

				   $mysock = getimagesize($image_temp);

					$target=$widthadd;

					$width = $mysock[0];

					$height = $mysock[1];

					if ($width > $height)

					{

						$percentage = ($target / $width);

					} else 

					{

						$percentage = ($target / $height);

					} 	

				

					$width = round($width * $percentage);

					$height = round($height * $percentage); 		

				 

					 $SMALL_IMAGE_NEW_WIDTH= $widthadd;

					 $SMALL_IMAGE_NEW_HEIGHT= $heightadd; 

					 

				   if($image_type=="image/jpeg" || $image_type=="image/pjpeg")

				   {

						$smallimage_name="thumb".$v_value.".jpg";

						$smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;

						$im = ImageCreateFromJPEG($image_temp);

						if(!$im)

						$Error = 6;

					}

					

					if($image_type=="image/gif")

					{

						//echo $smallimage_name="thumb".$v_value.".gif";

					$smallimage_name="thumb".$v_value.".gif";

				    $smallimage_path =$SMALL_IMAGE_PATH."/".$smallimage_name;

					$image_temp;

					$im = ImageCreateFromGIF($image_temp);

					}

					 

					 $OldWidth  = ImageSX($im);

					 $OldHeight = ImageSY($im);

					 $small_image = imagecreatetruecolor ($widthadd, $heightadd );

					 ImageCopyResized($small_image,$im,0,0,0,0,$widthadd, $heightadd, $OldWidth,$OldHeight);

					 ImageJpeg($small_image,$smallimage_path,$widthadd);

								 

					 //$bigimagename=time();



						if($image_type=="image/jpeg" || $image_type=="image/pjpeg")

						{

							$bigimagename = "big".$v_value.".jpg";

						}

						else if($image_type=="image/gif")

						{

							$bigimagename = "big".$v_value.".gif";

						}



					 $bigimagepath = $bigimage."/".$bigimagename;

					 $LARGE_IMAGE_NEW_WIDTH = $OldWidth;

					 $LARGE_IMAGE_NEW_HEIGHT = $OldHeight;

								 

					 $big_image = imagecreatetruecolor ($LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT );

					 ImageCopyResized($big_image,$im,0,0,0,0, $LARGE_IMAGE_NEW_WIDTH, $LARGE_IMAGE_NEW_HEIGHT , $OldWidth,$OldHeight);

					 ImageJpeg($big_image,$bigimagepath,100);

					 

					 

					 @copy($big_image, $bigimagepath);

					

					 if($bigimagename && $smallimage_name)

					  {

					 	$imagenames = array($bigimagename, $smallimage_name);	

						return $imagenames;

					 }	

					

				} 

			}	

		}    

	}
	

function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}

//NEW resize function for image resize in specific size
	function resize_multiple_images_new($file_parameter,$width_array,$path_array,$height_array,$dbi=100)
	{
	$image =$file_parameter["name"];
	$uploadedfile = $file_parameter['tmp_name'];

		if ($image)
		{
		$filename = stripslashes($file_parameter['name']);
		$extension = getExtension($filename);
		$extension = strtolower($extension);
	
		//if($extension == 'gif')
		//{
		resize_multiple_images_gif($file_parameter,$width_array,$path_array,$height_array,$dbi=100);
		//}
		//else
		//{
		//	resize_multiple_images_other_than_gif($file_parameter, $width_array, $height_array, $newfilename, $path_array);
		//}
		}
	}
	
	
	function resize_multiple_images_gif($file_parameter,$width_array,$path_array,$height_array,$dbi=100)
	{
	$image =$file_parameter["name"];
	$uploadedfile = $file_parameter['tmp_name'];


	if($image)
	{
	$filename = stripslashes($file_parameter['name']);
	$extension = getExtension($filename);
	$extension = strtolower($extension);

	if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
	{
	$change='<div class="msgdiv">Unknown Image extension </div> ';
	$errors=1;
	return "error";
	}
	else
	{
	$size=filesize($file_parameter['tmp_name']);

	if ($size > MAX_SIZE*1024)
	{
	$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
	$errors=1;
	}
	if($extension=="jpg" || $extension=="jpeg" )
	{
	$uploadedfile = $file_parameter['tmp_name'];
	$src = imagecreatefromjpeg($uploadedfile);
	}
	else if($extension=="png")
	{
	$uploadedfile = $file_parameter['tmp_name'];
	$src = imagecreatefrompng($uploadedfile);
	}
	else
	{
	$src = imagecreatefromgif($uploadedfile);
	}
	echo $scr;
	list($width,$height)=getimagesize($uploadedfile);
	for($i=0;$i<sizeof($width_array);$i++)
	  {
		  if($height_array){
		  $newheight = $height_array;
		  }
		  else{
		  $newheight=($height/$width)*$width_array[$i];
		  }
		  $newwidth=$width_array[$i];
		
		  $tmp=imagecreatetruecolor($newwidth,$newheight);
		
		  imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
		  $filename = $path_array[$i].$file_parameter['name'];
		  imagejpeg($tmp,$filename,$dbi);
		
		  imagedestroy($tmp);
		  }
		
		  imagedestroy($src);
		  return($file_parameter['name']);
		  }
	  }
}


?>